<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>淘有货后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/static/images/logo/favicon.ico"
          type="image/x-icon"/>
    <%--<link rel="shortcut icon" href="${pageContext.request.contextPath}/font/favicon.ico" type="image/x-icon"/>--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/main/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/main/xadmin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/swiper.min.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/login/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/swiper.jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/main/xadmin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/api/adminStore.js"></script>

</head>
<body>
<!-- 顶部开始 -->
<div class="container">
    <jsp:include page="../header.jsp"/>
</div>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 左侧菜单开始 -->
    <jsp:include page="../menu.jsp"/>
    <!-- 左侧菜单结束 -->
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form xbs" action="">
                <div class="layui-form-pane" style="text-align: center;">
                    <div class="layui-form-item" style="display: inline-block;">
                        <!-- <label class="layui-form-label xbs768">日期范围</label>
            <div class="layui-input-inline xbs768">
              <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
            </div>
            <div class="layui-input-inline xbs768">
              <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
            </div>时间选择器 -->
                        <!-- 	<div class="layui-input-inline">
                                <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div> -->
                        <!-- 	<div class="layui-input-inline" style="width:80px">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                            </div> -->
                    </div>
                </div>
            </form>
            <xblock>
                <div>
                    <button style="float: right" class="layui-btn layui-btn-small layui-btn-normal" onclick="findhistoryAll()"><i class="layui-icon">&#xe640;</i>查看历史订单
                    </button>
                </div>
            </xblock>
            <table class="layui-table">
                <thead>
                <tr>
                    <th>
                        ID
                    </th>
                    <th>
                        收货人姓名
                    </th>
                    <th>
                        总价
                    </th>
                    <th>
                        地址
                    </th>
                    <th>

                    </th>
                    <th>

                    </th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${orders}" var="item" >
                        <tr>
                            <td>
                                    ${fn:substring(item.oid, 0,10)}..
                            </td>
                            <td>
                                    ${item.name}
                            </td>
                            <td>
                                    ${item.totalPrice}
                            </td>
                            <td>
                                    ${item.address}
                                <c:if test="${item.state == '3'}">（已签收）</c:if>
                            </td>
                            <td>
                                <c:if test="${item.state == '0'}">
                                    <span>用户未付款</span>
                                </c:if>
                                <c:if test="${item.state == '1'}">
                                    <span onclick="order_shipments(this,'${item.oid}')"
                                          class="layui-btn layui-btn-small ">发货</span>
                                </c:if>
                                <c:if test="${item.state == '2'}">
                                    <span>快递正在运输</span>
                                </c:if>
                                <c:if test="${item.state == '3'}">
                                    <span>快递已被签收</span>
                                </c:if>
                                <c:if test="${item.state == '4'}">
                                    <span>交易已关闭</span>
                                </c:if>
                            </td>
                            <td class="td-manage">
                                <a title="详情" href="javascript:;" onclick="todetail('${item.oid}','${item.uid}')"
                                   style="text-decoration:none">
                                    <i class="layui-icon">&#xe615;</i>
                                </a>
                                <a title="删除" href="javascript:;" onclick="order_del(this,'${item.oid}','${item.uid}','${item.state}')"
                                   style="text-decoration:none">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                    <%--</c:if>--%>
                </c:forEach>
                </tbody>
            </table>
            <!-- 右侧内容框架，更改从这里结束 -->
        </div>
    </div>
    <!-- 右侧主体结束 -->
</div>
<!-- 中部结束 -->
<!-- 底部开始 -->
<!-- 		<div class="footer">
			<div class="copyright">Copyright ©2017 x-admin v2.3 All Rights Reserved. 本后台系统由X前端框架提供前端技术支持</div>
		</div> -->
<!-- 底部结束 -->
<!-- 背景切换开始 -->
<jsp:include page="../imagechange.jsp"/>
<!-- 背景切换结束 -->
<!-- 页面动态效果 -->
<script>
    /*等级-删除*/
    order_del = function (obj, oid,uid,state) {
        layer.confirm('确认要删除吗？', function (index) {
            if(state == "3" || state == "4"){
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/order/delOrder.do",
                    data: {
                        oid: id,
                        uid:uid
                    },
                    success: function (s) {
                        if (s.success) {
                            //发异步删除数据
                            $(obj).parents("tr").remove();
                            layer.msg('已删除!', {
                                icon: 1,
                                time: 1000
                            });
                        } else {
                            alert(s.msg);
                        }
                    }
                })
            }else {
                layer.msg("交易尚未结束",{
                    icon:1,
                    time:1000
                 })
            }
        });
    }

    order_shipments = function (obj, oid) {
        $.ajax({
            url: adminStore.context + "/order/shipments.do",
            type: "post",
            data: {
                oid: oid,
            },
            success: function (d) {
                if (d == "-1") {
                    top.location.href = adminStore.context + "/index.do";
                }
                if (d == "1") {
                    $(obj).removeClass();
                    $(obj).html("快递员正在前往揽收");
                    layer.msg("已提醒快递员揽收", {
                            icon: 1,
                            time: 1000
                        }
                    )
                }
            }
        })
    }

    findhistoryAll = function () {
        top.location.href = adminStore.context + "/order/findHistoryOrder.do";
    }


    // 自己写的
    //详情
    todetail = function (oid,uid) {
        var url = "${pageContext.request.contextPath}/order/tocheckOrder.do?oid=" + oid+"&uid="+uid;
        x_admin_show(
            "订单详情",
            url,
            "500", "400"
        )
    }

</script>
</body>
</html>
